package com.luo.demo;

import com.alibaba.fastjson.JSON;
import com.luo.mapper.UserMapper;
import com.luo.pojo.Course;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectMyNoCourseServlet")
public class HomePageSelectMyNoCourse extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/json;charset=utf-8");
        req.setCharacterEncoding("UTF-8");

        BufferedReader br = req.getReader();
        String params = br.readLine();

        SqlSession sqlSession = util00.useSqlSessionFactory().openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<Course> courses = mapper.selectMyNoCourse(params);
        String str = JSON.toJSONString(courses);
        resp.getWriter().write(str);

        sqlSession.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
